package com.heima.user.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

/**
 * @author: itheima
 * @create: 2022-07-10 11:00
 */
@Component
public class ShardingJob {

    /**
     * 分片任务
     * @return
     */
    @XxlJob("shardingJobHandler")
    public ReturnT<String> shardingJobHandler(){
        System.out.println("分片任务执行了");
        // 可参考Sample示例执行器中的示例任务"ShardingJobHandler"了解试用
        int shardTotal = XxlJobHelper.getShardTotal();
        int shardIndex = XxlJobHelper.getShardIndex();

        System.out.println("总执行器分片数量："+shardTotal);
        System.out.println("当前执行器分片索引："+shardIndex);

        return ReturnT.SUCCESS;
    }

}
